﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/5/25 星期六 21:28:53
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sector7.Framework.Utility;
using Sector7.Medical.EntityType;
using Sector7.Medical.Consts;

namespace Sector7.Medical.DAO.Utility
{
    /// <summary>
    /// 实体填充工具类
    /// </summary>
    public class FillEntityUtil
    {
        #region Public functions

        public static void ToDrug(object drug, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case C_ColumnName.DRUG_ID:
                case C_ColumnName.PHYSICAL_TYPE_ID:
                case C_ColumnName.NATURE_TYPE_ID:
                case C_ColumnName.DRUG_FORM_ID:
                case C_ColumnName.DRUG_NAME:
                case C_ColumnName.SPELL_CODE:
                case C_ColumnName.SPEC:
                case C_ColumnName.SPEC_UNIT_ID:
                case C_ColumnName.USAGE_UNIT_ID:
                case C_ColumnName.PRODUCT_NAME:
                case C_ColumnName.EXECUTIVE_STANDARD:
                case C_ColumnName.DRUG_REG_TYPE_ID:
                case C_ColumnName.DRUG_REG_NUMBER:
                case C_ColumnName.MANUFACTURER_ID:
                case C_ColumnName.IS_ON_SELL:
                case C_ColumnName.BAR_CODE:
                    ReflectionUtil.SetPropertyValue(drug, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToDrugType(object drugType, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                switch (propertyName)
                {
                    case C_ColumnName.DRUG_TYPE_ID:
                    case C_ColumnName.DRUG_TYPE_NAME:
                    case C_ColumnName.PARENT_ID:
                    case C_ColumnName.FLAGS:
                        ReflectionUtil.SetPropertyValue(drugType, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
        }

        public static void ToValueDomain(object valueDomain, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                switch (propertyName)
                {
                    case C_ColumnName.VALUE:
                    case C_ColumnName.IMPLICATION:
                    case C_ColumnName.DESCRIPTION:
                        ReflectionUtil.SetPropertyValue(valueDomain, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
        }

        public static void ToDrugStock(object drugStock, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                switch (propertyName)
                {
                    case C_ColumnName.STOCK_ID:
                    case C_ColumnName.DRUG_ID:
                    case C_ColumnName.BATCH_NUMBER:
                    case C_ColumnName.LOT_NUMBER:
                    case C_ColumnName.UNIT_ID:
                    case C_ColumnName.NUMBER:
                    case C_ColumnName.PRODUCED_DATE:
                    case C_ColumnName.AVAILABLE_DATE:
                    case C_ColumnName.IS_OVERDUE:
                        ReflectionUtil.SetPropertyValue(drugStock, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
        }

        public static void ToDrugPrice(object drugPrice, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                switch (propertyName)
                {
                    case C_ColumnName.PRICE_ID:
                    case C_ColumnName.DRUG_ID:
                    case C_ColumnName.UNIT_ID:
                    case C_ColumnName.PURCHASES_PRICE:
                    case C_ColumnName.SALES_PRICE:
                    case C_ColumnName.SPEC_ID:
                        ReflectionUtil.SetPropertyValue(drugPrice, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
        }

        public static void ToFrozenStock(object frozenStock, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                switch (propertyName)
                {
                    case C_ColumnName.FROZEN_ID:
                    case C_ColumnName.DRUG_ID:
                    case C_ColumnName.BATCH_NUMBER:
                    case C_ColumnName.LOT_NUMBER:
                    case C_ColumnName.UNIT_ID:
                    case C_ColumnName.NUMBER:
                        ReflectionUtil.SetPropertyValue(frozenStock, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
        }

        public static void ToDrugSpec(object drugSpec, string prefix, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(prefix))
            {
                propertyName = propertyName.Replace(prefix, "");

                ToDrugSpec(drugSpec, propertyName, propertyValue);
            }
        }

        public static void ToDrugSpec(object drugSpec, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case C_ColumnName.SPEC_ID:
                case C_ColumnName.DRUG_ID:
                case C_ColumnName.SPEC:
                case C_ColumnName.SPEC_UNIT_ID:
                case C_ColumnName.USAGE_UNIT_ID:
                case C_ColumnName.PACK_SPEC:
                case C_ColumnName.PACK_UNIT_ID:
                case C_ColumnName.STOCK_SPEC:
                case C_ColumnName.STOCK_UNIT_ID:
                    ReflectionUtil.SetPropertyValue(drugSpec, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        ////////////////////////////////////////////////////////////////////

        public static void ToDrugForm(object drugForm, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "DrugFormId":
                case "DrugFormName":
                    ReflectionUtil.SetPropertyValue(drugForm, propertyName, propertyValue);
                    break;
                case "DrugFormDescription":
                    ReflectionUtil.SetPropertyValue(drugForm, "Description", propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToDrugRegType(object drugRegType, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "DrugRegTypeId":
                case "DrugRegTypeName":
                    ReflectionUtil.SetPropertyValue(drugRegType, propertyName, propertyValue);
                    break;
                case "DrugRegTypeDescription":
                    ReflectionUtil.SetPropertyValue(drugRegType, "Description", propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToDrugPrice(object drugPrice, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case C_ColumnName.PRICE_ID:
                case C_ColumnName.PURCHASES_PRICE:
                case C_ColumnName.SALES_PRICE:
                case C_ColumnName.IS_ON_SELL:
                    ReflectionUtil.SetPropertyValue(drugPrice, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToMedicinalPrice(object medicinalPrice, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "MedPriceId":
                    if (propertyValue is DBNull)
                    {
                        medicinalPrice = null;
                    }
                    else
                    {
                        ReflectionUtil.SetPropertyValue(medicinalPrice, propertyName, propertyValue);
                    }
                    break;
                case "MedId":
                case "PriceUnitId":
                case "PurchasesPrice":
                case "SalesPrice":
                case "IsOnSell":
                    ReflectionUtil.SetPropertyValue(medicinalPrice, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToMedicinalStock(object medicinalStock, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "MedStockId":
                    if (propertyValue is DBNull)
                    {
                        medicinalStock = null;
                    }
                    else
                    {
                        ReflectionUtil.SetPropertyValue(medicinalStock, propertyName, propertyValue);
                    }
                    break;
                case "MedId":
                case "BatchNumber":
                case "LotNumber":
                case "StockUnitId":
                case "StockNumber":
                case "ProducedDate":
                case "AvailableDate":
                case "IsOverdue":
                    ReflectionUtil.SetPropertyValue(medicinalStock, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToUnit(object unit, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case C_ColumnName.UNIT_ID:
                case C_ColumnName.UNIT_NAME:
                case C_ColumnName.FLAGS:
                    ReflectionUtil.SetPropertyValue(unit, propertyName, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToUnit(object unit, string unitType, string propertyName, object propertyValue)
        {
            if (propertyName.Contains(unitType))
            {
                propertyName = propertyName.Replace(unitType, "");
                switch (propertyName)
                {
                    case C_ColumnName.UNIT_ID:
                        if (propertyValue is DBNull)
                        {
                            unit = null;
                        }
                        else
                        {
                            ReflectionUtil.SetPropertyValue(unit, propertyName, propertyValue);
                        }
                        break;
                    case C_ColumnName.UNIT_NAME:
                    case C_ColumnName.FLAGS:
                        ReflectionUtil.SetPropertyValue(unit, propertyName, propertyValue);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                ToUnit(unit, propertyName, propertyValue);
            }
        }

        public static void ToPhysicalType(object drugType, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "pId":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.DRUG_TYPE_ID, propertyValue);
                    break;
                case "pName":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.DRUG_TYPE_NAME, propertyValue);
                    break;
                case "pFlags":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.FLAGS, propertyValue);
                    break;
                default:
                    break;
            }
        }

        public static void ToNatureType(object drugType, string propertyName, object propertyValue)
        {
            switch (propertyName)
            {
                case "pId":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.PARENT_ID, propertyValue);
                    break;
                case "cId":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.DRUG_TYPE_ID, propertyValue);
                    break;
                case "cName":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.DRUG_TYPE_NAME, propertyValue);
                    break;
                case "cFlags":
                    ReflectionUtil.SetPropertyValue(drugType, C_ColumnName.FLAGS, propertyValue);
                    break;
                default:
                    break;
            }
        }

        #endregion

        #region Private functions
        #endregion
    }
}